#include "stdafx.h"
#include "Viewport.h"
#include <algorithm>

//////////////////////////////////////////////////////////////////////////
//! Find and erase element from container.
// @return true if item was find and erased, false if item not found.
//////////////////////////////////////////////////////////////////////////
template <class Container,class Value>
inline bool find_and_erase( Container& container,const Value &value )
{
	typename Container::iterator it = std::find( container.begin(),container.end(),value );
	if (it != container.end())
	{
		container.erase( it );
		return true;
	}
	return false;
}

void CViewManager::RegisterViewport( CViewport *pViewport )
{
	pViewport->SetViewManager(this);
	m_viewports.push_back(pViewport);
}

void CViewManager::UnregisterViewport( CViewport *pViewport )
{
	find_and_erase( m_viewports,pViewport );

}

void CViewManager::OnEditorNotifyEvent( EEditorNotifyEvent event )
{
	switch(event)
	{
	case eNotify_OnTest:
		UpdateTest();
		break;
	}

}

//////////////////////////////////////////////////////////////////////////
void CViewManager::UpdateTest()
{
	// Update each attached view,
	for (unsigned i = 0; i < m_viewports.size(); i++)
	{
		m_viewports[i]->Update();
	}
}

void CViewport::Update()
{
	std::cout<<"CViewport Update"<<std::endl;
}

void CRenderViewport::Update()
{
	std::cout<<"CRenderViewport Update"<<std::endl;
}

void C2DViewport::Update()
{
	std::cout<<"C2DViewport Update"<<std::endl;
}
